// request.js
import axios from 'axios';
import mpAdapter from "axios-miniprogram-adapter"
import config from '../config/myPageConfig';
axios.defaults.adapter = mpAdapter;

// 创建axios实例
const instance = axios.create({
	// baseURL:'http://kvxin.top/'
	baseURL: 'http://share.cs.kvxin.top',
	// baseURL: 'http://127.0.0.1:3011',
	// baseURL: 'https://2g59l88703.imdo.co',
	timeout: 10000,
});

// 请求拦截器
instance.interceptors.request.use(
	config => {
		let token;
		const userInfo = uni.getStorageSync('userInfo') || '';
		if (userInfo) {
			token = JSON.parse(userInfo).token
		} else {
			token = ''
		}
		config.headers['Authorization'] = token;
		// console.log("上传图片?", config);
		return config;
	},

	error => {
		// 请求错误处理
		return Promise.reject(error);
	}
);

// 响应拦截器
instance.interceptors.response.use(
	response => {
		return response.data;
	},
	error => {
		// 响应错误处理
		return Promise.reject(error);
	}
);

export default instance;